package com.icbci.process.listener;

import com.icbci.process.dao.ProcessDao;
import com.icbci.process.pojo.UserInfo;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.List;

//注册监听器
@WebListener
public class ManageUerInfoListener implements ServletContextListener {

    @Autowired
    private ProcessDao processDao;

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("查询用户信息。。。。。。。");
        List<UserInfo> list = processDao.getUserInfo();
        redisTemplate.opsForList().leftPushAll("user_info",list);
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("销毁用户信息。。。。。。");
        redisTemplate.delete("user_info");
    }


}
